<template>
	<view class="beijingse">
		<!-- 提现弹出层 -->
		<u-popup :show="show" :round="10" mode="center" @close="close">
			<view class="tanchuceng">
				<view class="tixianicon"></view>
				<view class="textcenter notitletext margin_top2">提现申请发起成功，正在处理中！</view>
				<view class="flexcenter">
					<view class="querenbtn margin_top5" @click="close">确认</view>
				</view>
			</view>
		</u-popup>
		<!-- 未认证弹框 -->
		<view>
			<u-popup :show="wrzshow" @close="wrzclose" mode="center" :round="10">
				<view>
					<view class="mainpadding">
						<view class="textcenter bigtext">温馨提示</view>
						<view class="huisetext textcenter margin_top7">{{rztext}}</view>
					</view>
					<view class="flexbetween margin_top7">
						<view class="quxiaobtn" @click="wrzshow = false">取消</view>
						<view class="renzbtn" @click="tzsmrz" v-if="personInfo.realname_status!=2">立即认证</view>
						<view class="renzbtn" @click="wrzshow = false" v-if="personInfo.realname_status==2">确定</view>
					</view>
				</view>
			</u-popup>
		</view>
		<view class="toububjt">
			<view class="xiaobtext" v-if="valueType==1">可提现金额（元）</view>
			<view class="xiaobtext" v-if="valueType==2">可提现积分</view>
			<view class="xiaobtext" v-if="valueType==3">可提现通证</view>
			<view class="xiaobtext" v-if="valueType==4">可提现本金（元）</view>
			<view class="xiaobtext" v-if="valueType==5">可提现收益（元）</view>
			<view class="margin_top2 dbaitext" v-if="valueType==1">{{personInfo.bonus_price}}</view>
			<view class="margin_top2 dbaitext" v-if="valueType==2">{{personInfo.integral_price}}</view>
			<view class="margin_top2 dbaitext" v-if="valueType==3">{{personInfo.token_price}}</view>
			<view class="margin_top2 dbaitext" v-if="valueType==4">{{token_price}}</view>
			<view class="margin_top2 dbaitext" v-if="valueType==5">{{sy_price}}</view>
		</view>
		<!--  -->
		<view class="mainpadding">
			<view class="neirong">
				<view class="mainpadding ffffff radius ">
					<view class="notitletext" v-if="valueType==1">提现金额 (元)</view>
					<view class="notitletext" v-if="valueType==2">提现积分</view>
					<view class="notitletext" v-if="valueType==3">提现通证</view>
					<view class="notitletext" v-if="valueType==4">提现本金 (元)</view>
					<view class="notitletext" v-if="valueType==5">提现收益 (元)</view>
					<view class="flexbetween margin_top">
						<view class="" style="flex: 5;">
							<input type="number" class="daheitext" v-model="txprice">
						</view>
						<view class="huangsetext" style="flex: 1.1;" v-if="valueType==1" @click="txprice = personInfo.bonus_price">全部提现</view>
						<view class="huangsetext" style="flex: 1.1;" v-if="valueType==2" @click="txprice = personInfo.integral_price">全部提现</view>
						<view class="huangsetext" style="flex: 1.1;" v-if="valueType==3" @click="txprice = personInfo.token_price">全部提现</view>
						<view class="huangsetext" style="flex: 1.1;" v-if="valueType==4" @click="txprice = token_price">全部提现</view>
						<view class="huangsetext" style="flex: 1.1;" v-if="valueType==5" @click="txprice = sy_price">全部提现</view>
					</view>
				</view>
				<view class="mainpadding ffffff radius margin_top">
					<view class="notitletext">提现至</view>
					<view class="flexbetween margin_top xiahuax" @click="changetype(1)">
						<view class="flexleft">
							<view class="weixin margin_right1"></view>
							<view class="notitletext">微信</view>
						</view>
						<!-- 已勾选 -->
						<view class="yigouxuan margin_right3" v-if="paytype==1"></view>
						<!-- 未勾选 -->
						<view class="weigouxuan margin_right3" v-if="paytype!=1"></view>
					</view>
					<view class="flexbetween margin_top xiahuax" @click="changetype(2)">
						<view class="flexleft">
							<view class="zhifub margin_right1"></view>
							<view class="notitletext">支付宝</view>
						</view>
						<!-- 已勾选 -->
						<view class="yigouxuan margin_right3" v-if="paytype==2"></view>
						<!-- 未勾选 -->
						<view class="weigouxuan margin_right3" v-if="paytype!=2"></view>
					</view>
					<view class="flexbetween margin_top" @click="changetype(3)">
						<view class="flexleft">
							<view class="yinhk margin_right1"></view>
							<view class="notitletext margin_right1">银行卡</view>
							<view class="huisetext" v-if="!personInfo.user_bank">（暂未绑卡点击去绑卡）</view>
							<view class="huisetext" v-if="personInfo.user_bank">{{personInfo.user_bank.open_bank}}
							</view>
						</view>
						<!-- 已勾选 -->
						<view class="yigouxuan margin_right3" v-if="paytype==3 && personInfo.user_bank"></view>
						<!-- 未勾选 -->
						<view class="weigouxuan margin_right3" v-if="paytype!=3 && personInfo.user_bank"></view>
					</view>
				</view>
				<view class="margin_top7 textcenter hongstext">*{{withdrawal_bz}}</view>
				<view class="bigbtn margin_top" @click.stop="tixianbtn">提现</view>
				<view class="bighuangsetext margin_top textcenter" @click="tztxjl">提现记录</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				wrzshow: false,
				valueType: 1, //1奖金，2积分，3通证，4本金，5收益
				paytype: 1,
				personInfo: {
					withdrawal_bonus_price: "", //奖金
					integral_price: "", //积分
					token_price: "", //通证
					voucher_price: "", //福利券
					"user_bank": {
						"id": 1,
						"bank_realname": "",
						"bank_cardno": "",
						"open_bank": "",
						"bank_address": "",
						"user_id": 2,
					},
					withdrawal_integral_price:"",
					withdrawal_token_price:"",
					realname_status:"",//实名认证状态
				},
				txprice:"",
				flag:true,//如果提现金额大于可提现金额为false
				rztext:"",
				withdrawal_bz:"",//提现备注,
				styc_account_id:'',
				token_price:'',// 本金
				sy_price:'',// 收益
			}
		},
		onLoad(options) {
			this.valueType = Number(options.type) + 1
			this.styc_account_id=options.styc_account_id||null
			this.getmsg()
		},
		onShow() {
			this.getinfo()
		},
		watch:{
			txprice(newval){
				let value1 = Number(newval)
				if(this.valueType==1){
					if(value1>Number(this.personInfo.bonus_price)){
						this.flag = false
					}else{
						this.flag = true
					}
				}
				if(this.valueType==2){
					if(value1>Number(this.personInfo.integral_price)){
						this.flag = false
					}else{
						this.flag = true
					}
				}
				if(this.valueType==3){
					if(value1>Number(this.personInfo.token_price)){
						this.flag = false
					}else{
						this.flag = true
					}
				}
				if(this.valueType==4){
					if(value1>Number(this.token_price)){
						this.flag = false
					}else{
						this.flag = true
					}
				}
				if(this.valueType==5){
					if(value1>Number(this.sy_price)){
						this.flag = false
					}else{
						this.flag = true
					}
				}
			}
		},
		methods: {
			getinfo() {
				httpRequest.request('/api/user/index', 'POST', {}, false, false, true).then(res => {
					if (res.code == 1) {
						this.personInfo = res.data
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
				if(this.valueType==4||this.valueType==5){
					httpRequest.request('/api/stycorder/myStycDetail', 'POST', {
						id:this.styc_account_id
					}, false, false, true).then(res => {
						if (res.code == 1) {
							this.token_price=res.data.token_price,
							this.sy_price=res.data.sy_price
						}
					}).catch(err => {
						httpRequest.toast(err.msg);
					})
				}
			},
			getmsg() {
				httpRequest.request('/api/index/getConfigInfo', 'POST', {}, false, false, true).then(res => {
					if (res.code == 1) {
						this.withdrawal_bz = res.data.withdrawal_bz
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			changetype(i) {
				this.paytype = i
				if (i == 3 && !this.personInfo.user_bank) {
					uni.navigateTo({
						url: "/pages/mypage/yinhangkbd"
					})
					return
				}
			},
			// 跳转实名认证
			tzsmrz() {
				this.wrzshow = false
				uni.navigateTo({
					url: '/pages/mypage/shimingrz'
				})
			},
			// 跳转绑定银行卡
			tzyhkbd() {
				uni.navigateTo({
					url: '/pages/mypage/yinhangkbd'
				})
			},
			// 跳转提现记录
			tztxjl() {
				if(this.personInfo.realname_status==1){
					this.rztext = "未实名认证无法进行操作！"
					this.wrzshow = true
					return false
				}else if(this.personInfo.realname_status==2){
					this.rztext = "您的实名认证处于待审核状态，暂时无法进行此类操作"
					this.wrzshow = true
					return false
				}else if(this.personInfo.realname_status==4){
					this.rztext = "您的实名认证验证失败，请重新认证"
					this.wrzshow = true
					return false
				}
				uni.navigateTo({
					url: '/pages/mypage/tixianjl?type='+this.valueType
				})
			},
			tixianbtn() {
				if(this.personInfo.realname_status==1){
					this.rztext = "未实名认证无法进行操作！"
					this.wrzshow = true
					return false
				}else if(this.personInfo.realname_status==2){
					this.rztext = "您的实名认证处于待审核状态，暂时无法进行此类操作"
					this.wrzshow = true
					return false
				}else if(this.personInfo.realname_status==4){
					this.rztext = "您的实名认证验证失败，请重新认证"
					this.wrzshow = true
					return false
				}
				if(this.txprice==""){
					httpRequest.toast("请输入提现金额")
					return false
				}
				let url=''
				let data={}
				if(this.valueType==4||this.valueType==5){
					url='/api/stycorder/addTx'
					data={
						token_price: this.txprice,
						styc_account_id: this.styc_account_id,
						ly: this.valueType==4?2:this.valueType==5?1:'',
						type: this.paytype
					}
				}else{
					url='/api/user/addWithdrawal'
					data={
						type:this.paytype,
						price:this.txprice,
						hb_type:this.valueType
					}
				}
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					if(res.code==1){
						this.show = true
					}else{
						httpRequest.toast(res.msg);
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			close() {
				this.show = false
				// console.log('close');
			},
			// 未认证弹框
			wrzclose() {
				this.wrzshow = false
				// console.log('close');
			},
		}
	}
</script>

<style lang="scss" scoped>
	.renzbtn {
		width: 291.5rpx;
		height: 74rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #fff;
		border-top: 1rpx solid #E7E7E7;
		// border-right:1rpx solid #E7E7E7;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		border-radius: 0 0 20rpx 0;
		color: #FAB536;
	}

	.quxiaobtn {
		border-radius: 0 0 0 20rpx;
		width: 291.5rpx;
		height: 74rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #fff;
		border-top: 1rpx solid #E7E7E7;
		border-right: 1rpx solid #E7E7E7;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.tanchuceng {
		padding: 40rpx 70rpx;
	}

	.tixianicon {
		height: 198rpx;
		width: 203rpx;
		background-size: 100% 100%;
		margin: auto;
		background-image: url('../../static/image/system/tixianicon.png');
	}

	.querenbtn {
		border-radius: 40rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		width: 328rpx;
		height: 64rpx;
		background-size: 100% 100%;
		display: flex;
		background-color: #FFC059;
		align-items: center;
		justify-content: center;
	}

	.bighuangsetext {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FAB536;
	}

	.hongstext {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF0303;
	}

	.huisetext {
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}

	.yinhk {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/yhk.png');
	}

	.weixin {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/weixin.png');
	}

	.zhifub {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		background-image: url('../../static/image/system/zhifub.png');
	}

	.xiahuax {
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.05);
	}

	.huangsetext {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FAB536;
	}

	.sishitext {
		font-size: 40rpx;
		font-family: DIN Next LT Pro-Regular, DIN Next LT Pro;
		font-weight: 400;
		color: #333333;
	}

	.daheitext {
		font-size: 64rpx;
		font-family: DIN Next LT Pro-Regular, DIN Next LT Pro;
		font-weight: 400;
		color: #333333;
	}

	.neirong {
		position: relative;
		top: -140rpx;
	}

	.dbaitext {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
	}

	.xiaobtext {
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
	}

	.toububjt {
		background-size: 100% 100%;
		width: 100%;
		padding: 20rpx 30rpx 0;
		height: 258rpx;
		box-sizing: border-box;
		background-image: url('../../static/image/system/tixian.png');
	}
</style>
